
package com.skytech.tax.customsdatawarehouse.fta.origincredential.domain.dao;


import com.skytech.tax.customsdatawarehouse.fta.origincredential.domain.entity.FtaOriginCredential;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class FtaOriginCredentialRepository {

    @Resource
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    private final String deleteOriginCredentialSql = "DELETE FROM fta_origin_credential WHERE id IN (:ids)";

    public void deleteBy(List<String> ids) {
        Map<String, Object> params = new HashMap<>();
        params.put("ids", ids);
        namedParameterJdbcTemplate.update(this.deleteOriginCredentialSql, params);
    }


    private final String insertOriginCredentialSql = "INSERT INTO fta_origin_credential (id, docNo, data, socialCreditCode, submitTime, storageTime)" +
            " VALUES (:id, :docNo, :data, :socialCreditCode, :submitTime, :storageTime)";


    public void save(List<FtaOriginCredential> ftaOriginCredentialList) {
        SqlParameterSource[] batch = SqlParameterSourceUtils.createBatch(ftaOriginCredentialList);
        namedParameterJdbcTemplate.batchUpdate(insertOriginCredentialSql, batch);
    }
}
